import Vue from 'vue'
import Vuex from 'vuex'
// import { getRoleType } from './module/commonData.js'
import { getRoleType } from './module/getData.js'
// import Http from '@/index.js'
Vue.use(Vuex)

export default new Vuex.Store({
  // 共享数据
  state: {
    $role: { 1: '管理员', 2: '供应商', 3: '工人', 4: '管家', 5: '设计师' },
    $state: { 1: '有效', 2: '无效', 3: '暂停', 4: '审核中' },
    // 退款状态1：审核中 2：已退款 3：已取消 4：退款审核未通过
    refundState: { 1: '审核中', 2: '已退款', 3: '已取消', 4: '退款审核未通过' },
    goodsState: { 0: '全部', 1: '已上架', 2: '未上架', 3: '已下架' },
    $orderGoodsState: { 1: '待付款', 2: '待服务', 3: '已取消', 4: '已删除', 5: '验收未通过', 6: '已完成（维保中）', 7: '退款审核中', 8: '已退款', 9: '服务中', 10: '待验收', 11: '退款审核未通过' },
    goodsStateOption: [
      { value: 0, label: '全部' },
      { value: 1, label: '已上架' },
      { value: 2, label: '未上架' },
      { value: 3, label: '已下架' }
    ],
    $roleOption: [
      { value: 1, label: '管理员' },
      { value: 2, label: '供应商' },
      { value: 3, label: '工人' },
      { value: 4, label: '管家' },
      { value: 5, label: '设计师' }
    ],
    $stateOption: [
      { value: 1, label: '有效' },
      { value: 2, label: '无效' },
      { value: 3, label: '暂停' },
      { value: 4, label: '审核中' }
    ],
    $orderStateOption: [
      { value: 1, label: '待付款' },
      { value: 2, label: '已付款' },
      { value: 3, label: '已取消' },
      { value: 4, label: '已删除' }
    ],
    $orderSplitOption: [
      { value: 1, label: '已拆单' },
      { value: 2, label: '无需拆单' }
    ],
    QuanOption: [
      { value: 1, label: '注册赠券' },
      { value: 2, label: '购物赠券' },
      { value: 3, label: '全场赠券' }
    ],
    meunList: [],
    gysList: [],
    roleList: []
  },
  mutations: {
    setMenu(state, data) {
      state.meunList = data
    },
    setGyslist(state, val) {
      state.gysList = val
    },
    setRolelist(state, val) {
      state.roleList = val
    }
  },
  actions: {
    getDatas({ dispatch, commit }, payload) {
      getRoleType(payload.type).then(res => {
        if (res.status === 200) {
          commit('setGyslist', res.data.data.data)
        }
      })
    },
    // 只能通过commit 触发mutations中的函数修改数据
    getMenu({ dispatch, commit }, payload) {
      // Http.post(payload.url, payload.data).then(res => {
      //   context.commit('setMenu', res.data.data)
      // })
      let list = [
        {
          authName: '商品管理',
          id: 1,
          order: null,
          path: 'goods',
          children: [
            {
              authName: '商品列表',
              id: 101,
              order: null,
              path: 'goods/goodsList',
              children: []
            },
            {
              authName: '商品分类',
              id: 102,
              order: null,
              path: 'goods/goodsCate',
              children: []
            },
            {
              authName: '品牌管理',
              id: 103,
              order: null,
              path: 'goods/brands',
              children: []
            }
          ]
        },
        {
          authName: '订单管理',
          id: 2,
          order: null,
          path: 'order',
          children: [
            {
              authName: '订单列表',
              id: 201,
              order: null,
              path: 'orders/ordersList',
              children: []
            }
            // {
            //   authName: '订单设置',
            //   id: 202,
            //   order: null,
            //   path: 'orders/ordersSet',
            //   children: []
            // }
          ]
        },
        {
          authName: '拆单管理',
          id: 3,
          order: null,
          path: 'splitOrder',
          children: [
            {
              authName: '拆单列表',
              id: 301,
              order: null,
              path: 'splitOrder/splitList',
              children: []
            }
          ]
        },
        {
          authName: '优惠券管理',
          id: 4,
          order: null,
          path: 'outGoods',
          children: [
            {
              authName: '优惠券列表',
              id: 341,
              order: null,
              path: 'quan/quanList',
              children: []
            }
          ]
        },
        {
          authName: '退货管理',
          id: 5,
          order: null,
          path: 'outGoods',
          children: [
            {
              authName: '退货列表',
              id: 501,
              order: null,
              path: 'outGoods/outGoodsList',
              children: []
            }
          ]
        },
        {
          authName: '系统管理',
          id: 6,
          order: null,
          path: 'seting',
          children: [
            {
              authName: '角色管理',
              id: 601,
              order: null,
              path: 'seting/roles',
              children: []
            },
            {
              authName: '用户管理',
              id: 602,
              order: null,
              path: 'seting/user',
              children: []
            }
          ]
        }
      ]
      commit('setMenu', list)
    }
  }
})
